package com.hhhn.wk.welcome;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;

import com.hhhn.wk.R;
import com.hhhn.wk.base.BaseActivity;
import com.hhhn.wk.main.MainActivity;
import com.hhhn.wk.utils.StatusBarUtil;

public class WelcomeActivity extends BaseActivity {
    private SharedPreferences preferences;
    private SharedPreferences.Editor editor;
    private final int SPLASH_DISPLAY_LENGHT = 2000; // 延迟3秒
    @Override
    protected void setOnCreateContentView() {
        setContentView(R.layout.activity_welcome);
        StatusBarUtil.setTransparentForImageViewInFragment(WelcomeActivity.this, null);
        preferences = getSharedPreferences("carousel", Context.MODE_PRIVATE);
        if (preferences.getBoolean("firststart", true)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    editor = preferences.edit();
                    //将登录标志位设置为false，下次登录时不在显示首次登录界面
                    editor.putBoolean("firststart", false);
                    editor.commit();
                    Intent intent=new Intent();

                    intent.setClass(WelcomeActivity.this,MainActivity.class);

                    startActivity(intent);
                    finish();
                }
            },SPLASH_DISPLAY_LENGHT);
        }else {
            loadData();
        }
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initClick() {

    }
    protected void loadData() {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 2000);
    }
}
